My Favourite Ridiculous Sorting Algorithms

From inefficiencies to absolute absurdities.

Posted November 24, 2024

It’s become precedent to do everything in the most efficient way possible and complete it the fastest we can. Sorting algorithms are fundamental in computer science, designed to sort data effectively and efficiently; and there can be as many as there are numbers in the world. Even with this, not all sorting algorithms were created with this intention and some are purposefully inefficient, overly complicated or just absurd – which makes them entertaining. The efficiency of these sorting algorithms can be given a time complexity in the form O(n), a time complexity describes the time required to execute an algorithm, the smaller the time complexity the faster the algorithm.

I’ve scoured the internet and brought together a collection of my favourite of them all listed below.

Bogosort

Bogosort written in Python

A bogosort is an iterative sorting algorithm that is particularly inefficient. The way it works is randomly shuffling elements of a list and then checking if they are correctly sorted, if not, the process is repeated. On average, the time complexity is O(n*n!). Although it could theoretically take forever.

Miracle Sort

Miraclesort written in Python

One of my favourite sorting algorithms is the miraclesort. The array is continuously checked until it is sorted. It requires an external force, such as a miracle, to change some bits in a way that it becomes sorted. (No time complexity for this one, miracles are timeless)

Bogobogosort

Bogobogosort written in Python

A bogobogosort is an even more inefficient sorting algorithm. It works by repeatedly applying a bogosort algorithm (as we covered earlier) to progressively large sub lists of the list until the entire list is sorted. This involves randomly shuffling elements of each sub list and checking if it is sorted and then repeating if not.

This results in an astronomically larger number of shuffles than a normal bogosort and a time complexity of O((n!)!) (a factorial of a factorial is a rather large number).

Stalinsort

Stalinsort written in Python

The Stalinsort is an interesting take on a sorting algorithm, but is by far the fastest one here, only taking a single iteration to sort the data. The Stalin sort iterates through the list and removes any element that is out of order, resulting in a sorted array on returning, although missing a part of its data. This gives a time complexity of O(n), as it only makes a single iteration.

Bozosort

Bozosort written in Python

Not to be confused with the bogosort, the bozosort is another iterative sorting algorithm. It checks if the list is sorted, and if not randomly swaps two elements in the list. This process is repeated until a sorted list is provided, giving a time complexity of O((n!)^n) in the worst case.

Jingle Sort

Image taken from Jingle Sort Video

To finish this collection, whilst researching some sorting algorithms, I came across the Jingle Sort, which I found rather bemusing. This works on a premise of “children = evil” as explained by Cube Drone on YouTube

For a jingle sort of n items, n+1 children should be used. Each of the n items should be wrapped up on December 24th and distributed for Christmas, with one child not receiving a gift. On Christmas morning, the children will open their gifts and compare them, sorting themselves in order, as children are greedy. The runtime for this is a minimum of two days, given you start on December 24th, and not being a conventional sorting algorithm it is difficult to speculate a time complexity. It is also rather difficult to express in code.

Conclusion: The Ridiculousness of Sorting Algorithms

Sorting algorithms are often celebrated for their elegancy in efficiency, but highlighted here are some with elegancy in inefficiency and absurdity. From chaotic randomness in a bogosort to ruthlessness in a Stalinsort, it is a pleasant reminder that impractical design is just as entertaining as optimisation.

Whilst none of these, especially a miraclesort or a Stalinsort, have no real-world application they still serve as illustrations of concepts such as iteration and randomness - key components in computer science - whilst sorting algorithms such as the Jingle sort give computer scientists creative freedom and sorting through unconventional humour.

If this was interesting or humorous, take a look into more unconventional sorting algorithms, or even create your own as it may become the next new absurdity.